package com.sds.sweng.swat.miplatform.ui.design.utils;

import org.apache.commons.lang.StringUtils;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;

import com.sds.sweng.swat.miplatform.ui.design.MiplatformUIDesignerActivator;

public class SWTUtils {

	private static Shell shell = new Shell(MiplatformUIDesignerActivator.getDefault().getWorkbench().getDisplay());

	public static void alert(Object message) {
		MessageBox alert = new MessageBox(shell);
		alert.setMessage(String.valueOf(message));
		alert.open();
	}

	public static boolean confirm(Object message) {
		MessageBox confirm = new MessageBox(shell, SWT.YES | SWT.NO);
		confirm.setMessage(String.valueOf(message));

		switch (confirm.open()) {
			case SWT.YES:
				return true;
			default:
				return false;
		}
	}

	public static boolean retry(Object message) {
		MessageBox confirm = new MessageBox(shell, SWT.RETRY | SWT.CANCEL);
		confirm.setMessage(String.valueOf(message));

		switch (confirm.open()) {
			case SWT.RETRY:
				return true;
			default:
				return false;
		}
	}

	public static void error(String message, Throwable e) {
		ErrorDialog error = new ErrorDialog(shell, StringUtils.EMPTY, message,
				new Status(IStatus.ERROR, MiplatformUIDesignerActivator.PLUGIN_ID, e.getMessage(), e), IStatus.ERROR);
		error.open();
	}

}
